import Page
from Page import Calendar
from Base.Base import Base
from selenium.webdriver.common.by import By


class CalendarIndexPage(Base):
    """
    日历首页

    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 左侧的home键
        self.calender_home_btn = (By.XPATH, Calendar.RESOURCE_ID.format("ivHome"))

        # 左侧的返回键
        self.calender_back_btn = (By.XPATH, Calendar.RESOURCE_ID.format('ivBack'))

        # 当前年份
        self.calender_current_year_text = (By.XPATH, Calendar.RESOURCE_ID.format("calendar_tv_year"))

        # 语音日程创建按钮
        self.calender_voice_btn = (By.XPATH, Calendar.RESOURCE_ID.format("add_schedule"))

        # 返回当前日期
        self.calender_return_date_btn = (By.XPATH, Calendar.RESOURCE_ID.format("back_current_day"))

        # 当前月份
        self.calender_current_month_img = (By.XPATH, Calendar.RESOURCE_ID.format("calender_month_picker"))

        # 星期标题
        self.calender_week_title_icon = (By.XPATH, Calendar.week_icon.format(""))

        # 日期天数阳历
        self.calender_date_fate_text = (By.XPATH, Calendar.today_fate_text.format(""))

        # 日期天数阴历
        self.calender_lunar_calendar_text = (By.XPATH, Calendar.lunar_calendar_text.format(""))

        # 语音图标
        self.calender_voice_icon = (By.XPATH, Calendar.RESOURCE_ID.format("iv_voice"))

        # 语音标题
        self.calender_voice_title_text = (By.XPATH, Calendar.RESOURCE_ID.format("tv_title"))

        # 语音内容
        self.calender_voice_connect_text = (By.XPATH, Calendar.RESOURCE_ID.format("tv_tip"))

    def click_home(self):
        """
        点击左侧的home键

        :return:None
        """
        self.click_element(self.calender_home_btn)

    def click_back(self):
        """
        点击左侧的back键

        :return:None
        """
        self.click_element(self.calender_back_btn)

    def get_current_year(self):
        """
        获取当前年份

        :return:获取元素
        """
        return self.find_element_o(self.calender_current_year_text)

    def click_voice(self):
        """
        点击语音创建按钮

        :return:None
        """
        self.click_element(self.calender_voice_btn)

    def click_return(self):
        """
        点击返回按钮

        :return:None
        """
        self.click_element(self.calender_return_date_btn)

    def get_current_month(self):
        """
        获取当前月份

        :return:获取元素
        """
        return self.find_element_o(self.calender_current_month_img)

    def get_week_title(self, index=1):
        """
        获取星期标题

        :return:获取元素
        """
        self.calender_week_title_icon = (By.XPATH, Calendar.week_icon.format(index))
        return self.find_element_o(self.calender_week_title_icon)

    def get_date_fate(self, index=1):
        """
        获取星期天数阳历

        :return:获取元素
        """
        self.calender_date_fate_text = (By.XPATH, Calendar.today_fate_text.format(index))
        return self.find_element_o(self.calender_date_fate_text)

    def get_lunar_calendar(self, index=1):
        """
        获取星期天数阴历

        :return:获取元素
        """
        self.calender_lunar_calendar_text = (By.XPATH, Calendar.lunar_calendar_text.format(index))
        return self.find_element_o(self.calender_lunar_calendar_text)

    def get_voice(self):
        """
        获取语音图标

        :return:获取元素
        """
        return self.find_element_o(self.calender_voice_icon)

    def get_voice_title(self):
        """
        获取语音标题

        :return:获取元素
        """
        return self.find_element_o(self.calender_voice_title_text)

    def get_voice_connect(self):
        """
        获取语音内容

        :return:获取元素
        """
        return self.find_element_o(self.calender_voice_connect_text)

    def swipe_data(self, direction):
        """
        滑动日期

        :return:获取元素
        [963,520][1081,610]
        [963,140][1081,230]
        """
        self.swipe_o(location=(1000, 1000, 180, 580), direction=direction)

    def is_display_calender_voice(self):
        """
        查看是否进入语音界面

        :return:
        """
        return self.is_display(self.calender_voice_title_text)

    def is_display_calender_index_year(self):
        """
        查看是否含有年份

        :return:
        """
        return self.is_display(self.calender_current_year_text)

    def is_display_calender_index_data(self):
        """
        查看是否含有星期

        :return:
        """
        return self.is_display(self.get_week_title)

    def is_display_calender_index_return(self):
        """
        查看是否含有返回按钮

        :return:
        """
        return self.is_display(self.calender_return_date_btn)

    def is_display_calender_index(self):
        """
        查看是否进入日历首页

        :return:
        """
        return self.is_display(self.calender_voice_btn)
